package generic

import "fmt"

func GenericDef() {
	// 泛型
	type mySlice[P int | string] []P
	type myMap[K int | string, V int | string] map[K]V
	type myList[T int | string] struct {
		sli              []T
		tmp1, tmp2, tmp3 T
	}

	// 定义变量
	mySli := mySlice[int]{1, 2, 3, 4, 5}
	myMp := myMap[int, string]{100: "哈哈", 90: "呵呵"}
	myLst := myList[string]{
		sli:  make([]string, 3, 3),
		tmp1: "哈哈",
		tmp2: "呵呵",
		tmp3: "噢噢",
	}

	fmt.Printf("mySli:%T\n", mySli)
	fmt.Printf("myMp:%T\n", myMp)
	fmt.Printf("myLst:%T\n", myLst)
	fmt.Println("====================================================")
}
